package com.dantwining.jade.oo;

import jade.core.behaviours.CyclicBehaviour;
import jade.lang.acl.ACLMessage;

import java.io.IOException;

public class TimeResponderJadeBehaviour extends CyclicBehaviour {

    @Override
    public void action() {
        ACLMessage message = myAgent.receive();

        if (message == null) {
            block();
            return;
        }

        long currentTime = System.currentTimeMillis();
        ACLMessage reply = message.createReply();
        try {
            reply.setContentObject(currentTime);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        myAgent.send(reply);
    }
}
